Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vector store endpoints and add assistants API v2 support #405

Merged
merged 6 commits into from
May 27, 2024

Conversation

gehrisandro
Copy link
Collaborator

This PR implements all changes for the assistants v2 API.

I started this PR as a fresh base to start with the v2 API, because reviewing a combination of 2 PRs seems too hard:

Co-authored-by: Kyle Nash <kylenash94@gmail.com>
@gehrisandro gehrisandro self-assigned this May 24, 2024
@gehrisandro gehrisandro changed the title Implement vector store endpoints Implement vector store endpoints and add assistants API v2 support May 25, 2024
@johngiaccotto
Copy link

johngiaccotto commented May 26, 2024

Hey @gehrisandro - When do you think you'll have the PR for the v2 assistants, threads and threads run resources ready? Thanks for you work on this.

@gehrisandro
Copy link
Collaborator Author

The commit for v2 is in progress.

Probably it will ready to try it out, later today.

@gehrisandro
Copy link
Collaborator Author

v2 support committed. Some further testing needed before release.

If one has some time to test and give feedback, any help is highly appreciated.

@DevJedis
Copy link

Am coming from a temporary #389 (comment) hack that was working.
When I cloned this branch to test, by trying both factory build and without.

The code:

try {
    $client->threads()->messages()->create($threadId, [
        'role' => 'user',
        'content' => $message,
    ]);
} catch (\Exception $e) {
    return $e->getMessage();
}

Errors:

PHP Warning:  Undefined array key "status" in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 77

Warning: Undefined array key "status" in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 77
PHP Warning:  Undefined array key "incomplete_details" in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 78

Warning: Undefined array key "incomplete_details" in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 78
PHP Warning:  Undefined array key "completed_at" in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 79

Warning: Undefined array key "completed_at" in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 79
PHP Warning:  Undefined array key "incomplete_at" in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 80

Warning: Undefined array key "incomplete_at" in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 80
PHP Fatal error:  Uncaught TypeError: OpenAI\Responses\Threads\Messages\ThreadMessageResponse::__construct(): Argument #5 ($status) must be of type string, null given, called in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 72 and defined in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php:32
Stack trace:
#0 /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php(72): OpenAI\Responses\Threads\Messages\ThreadMessageResponse->__construct()
#1 /home/ubuntu/openai-php/src/Resources/ThreadsMessages.php(31): OpenAI\Responses\Threads\Messages\ThreadMessageResponse::from()
#2 /home/ubuntu/openai-php/test.php(21): OpenAI\Resources\ThreadsMessages->create()
#3 {main}
  thrown in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 32

Fatal error: Uncaught TypeError: OpenAI\Responses\Threads\Messages\ThreadMessageResponse::__construct(): Argument #5 ($status) must be of type string, null given, called in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 72 and defined in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php:32
Stack trace:
#0 /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php(72): OpenAI\Responses\Threads\Messages\ThreadMessageResponse->__construct()
#1 /home/ubuntu/openai-php/src/Resources/ThreadsMessages.php(31): OpenAI\Responses\Threads\Messages\ThreadMessageResponse::from()
#2 /home/ubuntu/openai-php/test.php(21): OpenAI\Resources\ThreadsMessages->create()
#3 {main}
  thrown in /home/ubuntu/openai-php/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 32

Additional Context:

  1. PHP V: 8.3.7
  2. ThreadId used is one obtained from this same branch's Create Thread.

@gehrisandro
Copy link
Collaborator Author

Hi @DevJedis

Thanks for your comment. I have removed the fields, because they do not exist. This is an error in the OpenAI API documentation.

@julescole
Copy link

Hi, thanks for working on this. I'm getting the following error when using file search with the assistants v2 api.

"message": "Undefined array key "quote"",
"exception": "ErrorException",
"file": "/vendor/openai-php/client/src/Responses/Threads/Messages/ThreadMessageResponseContentTextAnnotationFileCitation.php",
"line": 38,

@gehrisandro
Copy link
Collaborator Author

Hi @julescole

According to the docs, the "quote" field is required and not nullable: https://github.com/openai/openai-openapi/blob/master/openapi.yaml#L11380

But sadly, often the docs are not accurate. Could you please provide a dump of the plain JSON response?

@gehrisandro gehrisandro changed the base branch from main to 0.10.x May 27, 2024 19:34
@gehrisandro
Copy link
Collaborator Author

@julescole I made the change, but would still like to see the raw JSON.
Thx 🙏🏼

@gehrisandro gehrisandro merged commit f32feb7 into 0.10.x May 27, 2024
16 checks passed
@julescole
Copy link

@julescole I made the change, but would still like to see the raw JSON. Thx 🙏🏼

Great, that's fixed it thanks. None of my citations seem to have the quote set. Here's a list from my most recent request, sorry, i wasn't sure how to output the raw json easily.

["annotations"]=>
            array(16) {
              [0]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(18) "【4:0†source】"
                ["start_index"]=>
                int(348)
                ["end_index"]=>
                int(360)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-rx4SHF4Jra6MnHJwW87WI5aJ"
                }
              }
              [1]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(18) "【4:1†source】"
                ["start_index"]=>
                int(360)
                ["end_index"]=>
                int(372)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-rx4SHF4Jra6MnHJwW87WI5aJ"
                }
              }
              [2]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(18) "【4:6†source】"
                ["start_index"]=>
                int(372)
                ["end_index"]=>
                int(384)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-rx4SHF4Jra6MnHJwW87WI5aJ"
                }
              }
              [3]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(18) "【4:3†source】"
                ["start_index"]=>
                int(568)
                ["end_index"]=>
                int(580)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-bPPJdGRF4DJfTVrd0LNV8QjZ"
                }
              }
              [4]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(18) "【4:4†source】"
                ["start_index"]=>
                int(580)
                ["end_index"]=>
                int(592)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-bPPJdGRF4DJfTVrd0LNV8QjZ"
                }
              }
              [5]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(18) "【4:2†source】"
                ["start_index"]=>
                int(739)
                ["end_index"]=>
                int(751)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-qrfz7EwfSdrhy4QAZv1E6HW4"
                }
              }
              [6]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(19) "【4:13†source】"
                ["start_index"]=>
                int(751)
                ["end_index"]=>
                int(764)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-qrfz7EwfSdrhy4QAZv1E6HW4"
                }
              }
              [7]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(18) "【4:5†source】"
                ["start_index"]=>
                int(877)
                ["end_index"]=>
                int(889)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-XL0onw6lc98x2S2cHTjJgCGS"
                }
              }
              [8]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(18) "【4:7†source】"
                ["start_index"]=>
                int(1016)
                ["end_index"]=>
                int(1028)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-TcOuVW9lGVLIWyo5Jqfn9YUI"
                }
              }
              [9]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(19) "【4:16†source】"
                ["start_index"]=>
                int(1028)
                ["end_index"]=>
                int(1041)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-p03m489p4UyKaa9p1OqjNeP0"
                }
              }
              [10]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(19) "【4:15†source】"
                ["start_index"]=>
                int(1173)
                ["end_index"]=>
                int(1186)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-kIdUeZTHSsWx4UPAOjDTOEMX"
                }
              }
              [11]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(19) "【4:17†source】"
                ["start_index"]=>
                int(1186)
                ["end_index"]=>
                int(1199)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-z5y0wppoZmLjJ8fbTffR8AJ0"
                }
              }
              [12]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(18) "【4:8†source】"
                ["start_index"]=>
                int(1330)
                ["end_index"]=>
                int(1342)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-RrLrJpldMqlmfhUlapVcjr0J"
                }
              }
              [13]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(19) "【4:10†source】"
                ["start_index"]=>
                int(1342)
                ["end_index"]=>
                int(1355)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-RrLrJpldMqlmfhUlapVcjr0J"
                }
              }
              [14]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(19) "【4:19†source】"
                ["start_index"]=>
                int(1503)
                ["end_index"]=>
                int(1516)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-i8f9Tz3K5IPtyxYwiqiwAU2E"
                }
              }
              [15]=>
              array(5) {
                ["type"]=>
                string(13) "file_citation"
                ["text"]=>
                string(19) "【4:12†source】"
                ["start_index"]=>
                int(1772)
                ["end_index"]=>
                int(1785)
                ["file_citation"]=>
                array(1) {
                  ["file_id"]=>
                  string(29) "file-WTORzTtPIbzH1BaCWGHgBJgB"
                }
              }
              ```

@nunomaduro nunomaduro deleted the add-assistants-v2-api branch May 28, 2024 12:08
@francost15
Copy link

How to implement the vector store with the wizard so that it can read it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants